package com.vueperson.vueperson.t1.streamTest;

import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import java.util.StringJoiner;
import java.util.stream.Stream;

public class StreamTest2 {
    public static void main(String[] args) {
        List<Integer> list = Arrays.asList(7, 6, 9, 3, 8, 2, 1);
        StringJoiner sj =new StringJoiner(",");
        //遍历输出符合条件和元素
        list.stream().filter(x->x>6).forEach(item->{
            sj.add(item.toString());
        });
        System.out.println(sj.toString());
        StringJoiner sj2 =new StringJoiner(",");

        //匹配第一个
        Optional<Integer> findFirst=list.stream().filter(x->x>6).findFirst();
        System.out.println(findFirst.get());


        //匹配任意
        Optional<Integer> findAny=list.parallelStream().filter(x->x>8).findAny();
        System.out.println(findAny.get());

        //是否有大于6的值
        boolean anyMatch =list.stream().anyMatch(x->x==2);
        System.out.println(anyMatch);
    }

}
